class GridsController < ApplicationController

  before_filter :grid_authorize, :except => ['index', 'edit']

  def index
    @grids = Grid.all
  end

  
  def new
    @grid = Grid.new
  end

  
  def edit
    @grid = Grid.find(params[:id]).to_json
    @account_type = current_user.account_type
  end

  
  def create
    @grid = Grid.new(params[:grid])

    if @grid.save
      redirect_to(:action => 'edit', :id => @grid.id)
    else
      render :action => 'new'
    end
    
  end
  
  def destroy
    @grid = Grid.find(params[:id])
    @grid.destroy
    redirect_to(:action => 'index')
  end

  private

  def grid_authorize
    if current_user.account_type != 'operator'
      flash[:notice] = t(:only_operator, :scope => 'flash')
      redirect_to :action => 'index'
    end
  end

  
end
